package org.project.task.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1071681926787951549L;
    private Integer code;
    private String message;
    private T data;

    public R<T> success(String message, T data) {
        this.setCode(200);
        this.setMessage(message);
        this.setData(data);
        return this;
    }

    public R<T> success(T data) {
        this.setCode(200);
        this.setMessage("操作成功");
        this.setData(data);
        return this;
    }

    public R<T> success(String message) {
        this.setCode(200);
        this.setMessage(message);
        this.setData(null);
        return this;
    }

    public R<T> error(T data) {
        this.setCode(500);
        this.setMessage(message);
        this.setData(data);
        return this;
    }


    public R<T> error(String message) {
        this.setCode(500);
        this.setMessage(message);
        this.setData(null);
        return this;
    }

    public R<T> error(String message, T data) {
        this.setCode(500);
        this.setMessage(message);
        this.setData(data);
        return this;
    }
}
